package com.note.app.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.note.common.domain.CollaborationSession;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 协作会话Mapper接口
 */
@Mapper
public interface CollaborationSessionMapper extends BaseMapper<CollaborationSession> {
    
    /**
     * 查询用户参与的协作会话
     *
     * @param userId 用户ID
     * @return 会话列表
     */
    @Select("SELECT s.* FROM collaboration_session s " +
            "JOIN collaboration_participant p ON s.id = p.session_id " +
            "WHERE p.user_id = #{userId} ORDER BY s.updated_at DESC")
    List<CollaborationSession> selectUserSessions(@Param("userId") Long userId);
    
    /**
     * 查询笔记的活跃会话
     *
     * @param noteId 笔记ID
     * @return 会话列表
     */
    @Select("SELECT * FROM collaboration_session WHERE note_id = #{noteId} AND status = 1")
    List<CollaborationSession> selectNoteActiveSessions(@Param("noteId") Long noteId);
    
    /**
     * 查询会话访问令牌
     *
     * @param sessionId 会话ID
     * @return 访问令牌
     */
    @Select("SELECT access_token FROM collaboration_session WHERE id = #{sessionId}")
    String selectAccessToken(@Param("sessionId") Long sessionId);
} 